﻿Imports BUS
Imports DTO
Public Class CapNhatKhoiLop

    Private Sub btnthoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat.Click
        Me.Close()
    End Sub

    Public Sub LayDanhsachtKhoiLop()
        dtgvdanhsachkhoilop.Rows.Clear()
        Dim _bus As New CKhoiLopBUS()
        Dim _danhsachkl As New List(Of CKhoiLopDTO)
        _danhsachkl = _bus.LayDanhSachKhoiLop()
        Dim i As Integer
        For i = 0 To _danhsachkl.Count - 1
            dtgvdanhsachkhoilop.Rows.Add(i + 1, _danhsachkl(i).MaKhoiLop, _danhsachkl(i).TenKhoiLop, _danhsachkl(i).SoLuongLop)
        Next

    End Sub

    Private Sub CapNhatKhoiLop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LayDanhsachtKhoiLop()
    End Sub

    Private Sub dtgvdanhsachkhoilop_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtgvdanhsachkhoilop.SelectionChanged

        If dtgvdanhsachkhoilop.CurrentRow.Index >= 0 Then
            txttenkhoilop.Text = dtgvdanhsachkhoilop.CurrentRow.Cells("cltenkhoilop").Value
            txtsoluonglop.Text = dtgvdanhsachkhoilop.CurrentRow.Cells("clsoluonglop").Value
        End If

    End Sub

    Private Sub btncapnhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncapnhat.Click
        Try
            Dim _KLdto As New CKhoiLopDTO()
            _KLdto.MaKhoiLop = dtgvdanhsachkhoilop.CurrentRow.Cells("clmakhoilop").Value
            _KLdto.TenKhoiLop = txttenkhoilop.Text
            _KLdto.SoLuongLop = Int32.Parse(txtsoluonglop.Text)
            Dim _bus As New CKhoiLopBUS()

            If _bus.CapNhatKhoiLop(_KLdto) > 0 Then
                MessageBox.Show("Cap Nhat Khoi Lop Thanh Cong")
                LayDanhsachtKhoiLop()
            Else
                MessageBox.Show("Cap Nhat Khoi Lop That Bai")
            End If

        Catch ex As Exception
            MessageBox.Show("Loi --> " + ex.ToString())
        End Try
    End Sub
End Class